'''

    This device reacts on the system event.

'''

#FIXME: set the PYTHONPATH and get ride of this:
import sys, os
shikPath = os.path.abspath('../../')
if shikPath not in sys.path:
    sys.path.append(shikPath)

import SHIK._sysevents
from SHIK.devices import KeyboardDevice

class SysKeyboard(KeyboardDevice):
    def __init__(self):
        super(SysKeyboard,self).__init__()
        self.DEBUG = SHIK._sysevents.DEBUG
        SHIK._sysevents.init()
        SHIK._sysevents.add_key_press(self.on_press)
        SHIK._sysevents.add_key_release(self.on_release)

    def enable(self, b):
        '''
        Overridden to let the event filter act accordingly.
        '''
        KeyboardDevice.enable(self,b)
        SHIK._sysevents.enable(b)

    def emit(self, data):
        #print "SYSKEYBOAD EMIT", data
        SHIK._sysevents.emit(data)
        
if __name__ == '__main__':
    import time
    SHIK._sysevents.DEBUG(True)
    skb = SysKeyboard()
    def Listener(device, func_name):
        print "DEVICE SAID:", func_name
    skb.add_listener(Listener)
    nbSec = 10
    to_emit = "Damien 909"
    print "Start for "+repr(nbSec)+" secs:"
    for i in range(nbSec):
        print ' ', i
        time.sleep(1)
        skb.emit(to_emit[i])
    
    print "Stop."
    